import { createStore } from 'redux'



//从redux-persist插件中导入实现store持久化的方法
import { persistStore, persistReducer } from 'redux-persist'
//导入持久化存储引擎 localStorage sessionStorage
import storage from 'redux-persist/lib/storage' //默认存储在localStorage
// import storage from 'redux-persist/lib/storage/session' //默认存储在sessionStorage




//导入纯函数( 根ruducer )
import {rootReducer} from './reducer'




//使用persistReducer对根reducer进行持久化处理
const persistedReducer = persistReducer( { key:'redux',storage } , rootReducer)

//使用持久化处理后的根reducer 创建store
export var store = createStore(persistedReducer)

//使用persistStore对store进行持久化处理
export var persistor = persistStore(store)


//store身上的核心方法:
//store.dispatch()  触发action ( 在想要修改store中的数据时调用 )
//store.getState()  获取store中的state数据
//store.subscribe() 监听store中state数据的变化